package cn.lang.manager;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author Lang 1102076808@qq.com
 * @description 节假日外部服务
 * @date 2020-10-30 22:39
 */

@Component
public class HolidayApiManager {

	/**
	 * @description 普通节假日
	 * @author Lang 
	 * @date 2020/10/30 22:39
	 */
	 public JSONObject getHolidayInfo(Date date){
		 String res = HttpUtil.get("http://timor.tech/api/holiday/info/" + DateUtil.format(date, "yyyy-MM-dd"));
		 JSONObject jsonObject = JSONUtil.parseObj(res);
		 return jsonObject;
	 }

	/**
	 * @description 在一起的纪念日
	 * @author Lang
	 * @date 2020/10/30 22:56
	 */
	public  JSONObject loveDay(Date date) {
		DateTime dateTime = DateTime.of("20190507", "yyyyMMdd");
		long day = DateUtil.betweenDay(date, dateTime, true) + 1;
		String name = "";
		int code = 0;
		if (day % 100 == 0) {
			name = "张总和刘秘书在一起的第 " + day + " 天";
			code = 1;
		}
		if (StrUtil.equals("0507", DateUtil.format(date, "MMdd"))) {
			long year = DateUtil.betweenYear(date, dateTime, true);
			name = "张总和刘秘书在一起的 " + year + " 周年纪念日";
			code = 1;
		}

		JSONObject jsonObject = new JSONObject();
		jsonObject.set("code",code);
		jsonObject.set("name",name);
		return jsonObject;
	}
}
